﻿using RabbitMQ.Client;
using RabbitMQ.Client.Events;
using System;
using System.Text;

namespace ElseLoggerApp
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("Hello World!");
            var channel = Common.RabbitMQ.GetChannel();

            //交换机
            channel.ExchangeDeclare("myexchange", ExchangeType.Direct, true, false, null);

            //队列
            channel.QueueDeclare("else_logger", true, false, false, null);

            foreach (var item in new string[] { "info", "debug" })
            {
                //绑定交换机
                channel.QueueBind("else_logger", "myexchange", item, default);
            }

            var consumerEvent = new EventingBasicConsumer(channel);

            consumerEvent.Received += (sender, e) =>
            {
                var msg = Encoding.UTF8.GetString(e.Body.ToArray());
                Console.WriteLine(msg);
            };
            channel.BasicConsume("else_logger", true, consumerEvent);

            Console.ReadKey();
        }
    }
}
